<?php
class isp_customer_invoice_tdk_langgan_model extends MY_Model {
	var $model = 'isp_customer_invoice_tdk_langgan';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT
					a.kode_curtomer as kode_customer,
					b.nama,
					b.nama_perusahaan,
					b.alamat,
					b.kota,
					b.tgl_aktifasi,
					b.tgl_due,
					b.tgl_berakhir,
					a.periode_tagihan,
					c.nama_inventori as nama_produk,
					c.harga as harga_produk,
					c.banyak as banyak_produk,
					FROM
					ISP_CLIENT_INVOICE_TDK_LANGGAN a
					LEFT JOIN ISP_CUSTOMER b
					on a.kode_curtomer = b.kode_customer
					LEFT JOIN ISP_INVENTORI c
					on c.no_invoice = b.kode_produk		
					WHERE	(UPPER(a.kode_curtomer) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(b.nama) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'a.kode_curtomer' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
				         
                   
				
		return json_encode( $this->paging($ls_sql) );
	}

	function GetJSON2()
	{
		$ls_sql	= "	SELECT
					b.kode_customer,
					b.nama as nama_customer,
					a.harga_satuan,
					a.jumlah,
					a.nama_produk
					FROM isp_pembelian_produk a				
					LEFT JOIN isp_customer b
					on a.kode_customer = b.kode_customer
					WHERE  (UPPER(b.kode_customer) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(b.nama) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'b.kode_customer' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));		
		return json_encode( $this->paging($ls_sql) );
	}

	function Add($arr_data){
		$this->db->insert('isp_client_invoice_tdk_langgan', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('isp_client_invoice_tdk_langgan', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_no_invoice){
		$result = $this->db->get_where('isp_client_invoice_tdk_langgan', array('no_invoice' => $as_no_invoice));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_no_invoice)
	{
		$result = $this->db->get_where('isp_client_invoice_tdk_langgan', array('no_invoice' => $as_no_invoice));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM isp_client_invoice_tdk_langgan WHERE no_invoice = '".$arr_rule['no_invoice']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['no_invoice']."]<br />";
			}else{
				$this->db->delete('isp_client_invoice_tdk_langgan', array('no_invoice' => $arr_rule['no_invoice']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>